import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class Main1 {
    public static void main(String[] args) {
        try {
            // XML 字符串
            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<parent>\n" +
                    "    <children>\n" +
                    "        <record>\n" +
                    "            <name>Alice</name>\n" +
                    "            <age>10</age>\n" +
                    "            <record>\n" +
                    "                <a>1</a>\n" +
                    "            </record>\n" +
                    "            <record>\n" +
                    "                <a>2</a>\n" +
                    "            </record>\n" +
                    "        </record>\n" +
                    "    </children>\n" +
                    "</parent>";

            // 创建JAXB上下文
            JAXBContext context = JAXBContext.newInstance(Parent.class);

            // 创建Unmarshaller
            Unmarshaller unmarshaller = context.createUnmarshaller();

            // 将XML字符串转换为Java对象
            Parent parent = (Parent) unmarshaller.unmarshal(new StringReader(xml));

            // 输出结果
            System.out.println("Parent Object:");
//            for (Record record : parent.getChildren()) {
//                System.out.println("Name: " + record.getName());
//                System.out.println("Age: " + record.getAge());
//                for (SubRecord subRecord : record.getRecords()) {
//                    System.out.println("SubRecord a: " + subRecord.getA());
//                }
//            }
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
}
